import React from 'react';
import { withRouter, Link } from 'react-router';
import Widget from '../mui/Widget.js';
import Tool from '../../utils/ToolUtils.js';

const userInfo = withRouter(
  React.createClass({
    getInitialState() {
      return {
        userName: Tool.locals.getSession('username')
      };
    },
    componentWillMount() {
      const token = Tool.locals.getSession('token');
      if (!token) {
        this.props.router.push('/');
      }
    },
    logOut() {
      Tool.locals.setSession('token', '');
      Tool.locals.setSession('username', '');
      this.props.router.push('/');
    },
    render() {
      return (
        <div>
          <Widget widgetHeader={'账号管理'} />
          <div className="form-group">
            <label className="show-label" htmlFor="name">账号</label>
            <div className="show-group">
              <span>{this.state.userName}</span>
            </div>
            <div className="show-group">
              <a className="color-red" onClick={this.logOut}>注销</a>
            </div>
          </div>
          <div className="form-group">
            <label className="show-label" htmlFor="name">密码</label>
            <div className="show-group">
              <Link to="/userManage/editPasswd" activeClassName="active" className="btn btn-primary">修改密码</Link>
            </div>
          </div>
        </div>
      );
    }
  })
);

export default userInfo;
